package com.dkd.day20250712;

import java.sql.SQLOutput;
import java.util.LinkedList;
import java.util.Scanner;

public class Main11 {
    public static void main(String[] args) {
        //在星球争霸篮球赛对抗赛中，最大的宇宙战队希望每个人都能拿到MVP，MVP的条件是单场最高分得分获得者。
        //可以并列所以宇宙战队决定在比赛中尽可能让更多队员上场，并且让所有得分的选手得分都相同，
        //然而比赛过程中的每1分钟的得分都只能由某一个人包揽。
        //
        //
        //
        //输入描述
        //输入第一行为一个数字 t ，表示为有得分的分钟数 1 ≤ t ≤ 50
        //第二行为 t 个数字，代表每一分钟的得分 p， 1 ≤ p ≤ 50
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        LinkedList<Integer> list = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }

        System.out.println(solve(list,n));
    }

    public static int solve(LinkedList<Integer> list,int n) {
        //倒序排序
        list.sort((a,b)->b-a);
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += list.get(i);
        }

        while(n > 1) {

           if(solve2(list,n,sum)) return sum/n;
           n--;
        }

        return sum;
    }

    public static boolean solve2(LinkedList<Integer> list,int m,int sum) {
        if(sum% m !=0) return false;

        int target = sum/m;

        if(target < list.get(0)) return false;

   //     while(list.size() > 1 &&list.get(0)==target) m--;

        int [] bucket = new int[m];
        boolean flag = solve3(list,0,target,bucket);

return flag;
    }

    public static boolean solve3(LinkedList<Integer> list,int index,int target,int[] bucket) {
/*        if(index == list.size()) return true;
            for (int i = 0; i < bucket.length; i++) {
                if(bucket[i]+list.get(index) <= target) {
                    bucket[i] = bucket[i]+list.get(index);
                    if(solve3(list,index+1,target,bucket)) return true;
                    bucket[i] = bucket[i]-list.get(index);
                    if(bucket[i]==0) return false;
                }
            }
        return false;*/

/*        if (index == list.size()) return true;

        int select = list.get(index);

        for (int i = 0; i < bucket.length; i++) {
          //  if (i > 0 && bucket[i] == bucket[i - 1]) continue;
            if (select + bucket[i] <= target) {
                bucket[i] += select;
                if (solve3(list, index + 1, target, bucket)) return true;
                bucket[i] -= select;
            }
        }*/

        //循环终止条件
        if(index == list.size()) return true;

        for(int i = 0; i < bucket.length; i++) {
            if(bucket[i] + list.get(index) <= target) {
                bucket[i] = bucket[i] + list.get(index);
                if(solve3(list,index+1,target,bucket)) return true;
                bucket[i] -=  list.get(index);
            }
        }

        return false;
    }
}
